package com.logistics.security;

/**
 * 用户上下文工具类
 */
public class UserContext {
    
    private static final ThreadLocal<CurrentUser> userHolder = new ThreadLocal<>();
    
    /**
     * 设置当前用户
     */
    public static void setCurrentUser(CurrentUser user) {
        userHolder.set(user);
    }
    
    /**
     * 获取当前用户
     */
    public static CurrentUser getCurrentUser() {
        return userHolder.get();
    }
    
    /**
     * 清除当前用户
     */
    public static void clear() {
        userHolder.remove();
    }
    
    /**
     * 当前用户信息
     */
    public static class CurrentUser {
        private Long id;
        private String username;
        private Long tenantId;
        private Long siteId;
        private String role;
        
        public CurrentUser() {}
        
        public CurrentUser(Long id, String username, Long tenantId, Long siteId, String role) {
            this.id = id;
            this.username = username;
            this.tenantId = tenantId;
            this.siteId = siteId;
            this.role = role;
        }
        
        // Getters and setters
        public Long getId() { return id; }
        public void setId(Long id) { this.id = id; }
        
        public String getUsername() { return username; }
        public void setUsername(String username) { this.username = username; }
        
        public Long getTenantId() { return tenantId; }
        public void setTenantId(Long tenantId) { this.tenantId = tenantId; }
        
        public Long getSiteId() { return siteId; }
        public void setSiteId(Long siteId) { this.siteId = siteId; }
        
        public String getRole() { return role; }
        public void setRole(String role) { this.role = role; }
    }
}
